import { defineStore } from 'pinia'
import { connectRabbitMQ, disconnectRabbitMQ } from '@/assets/js/rabbitmq'

export default defineStore(
  'rabbitmq',
  {
    state() {
      return {
        message: '',
      }
    },
    actions: {
      initializeRabbitMQ() {
        connectRabbitMQ((message) => {
          this.message = message // 收到消息时将其添加到 messages 列表中
        })
      },

      // 断开 RabbitMQ 连接
      disconnectRabbitMQ() {
        disconnectRabbitMQ()
      },
    },
    getters: {},
  },
  {
    persist: true,
  }
)

